package com.ghn.cocknovel.ui.activity.start.vm

/**
 *@author: Administrator
 *2023/9/28
 *desc:
 */


import android.app.Application
import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.example.basemodel.base.BaseViewModel
import com.ghn.cocknovel.ext.setIsLogin
import com.ghn.cocknovel.ext.setUserAccount
import com.ghn.cocknovel.ext.setUserPassWord
import com.ghn.cocknovel.net.DataService
import com.ghn.cocknovel.ui.activity.main.MainActivity
import com.google.gson.Gson
import com.kt.NetworkModel.bean.LoginBean
import com.kt.NetworkModel.net.CallBack
import com.kt.NetworkModel.net.RxUtils
import com.kt.NetworkModel.utils.MVUtils

/**
 * @author 浩楠
 *
 * @date 2023/1/9   16:11.
 *
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * 描述:
 */
open class StartViewModel(application: Application) : BaseViewModel(application) {
    companion object {
        val TAG: String? = StartViewModel::class.simpleName

    }

    val mLogin = MutableLiveData<LoginBean>()
    /**
     * 跳转到首页
     */
    fun getMain(username: String, password: String) {
        DataService.login(username, password).compose(RxUtils.mainSync()).subscribe(object : CallBack<LoginBean>() {
            override fun onResult(result: LoginBean?) {
                Log.i(TAG, "onResult: $result")
                result?.also {
                    mLogin.value=it
                    MVUtils.setUserAccount(username)
                    MVUtils.setUserPassWord(password)
                    MVUtils.put("userData", Gson().toJson(result))
                    MVUtils.setIsLogin(true)
//                    startActivity(MainActivity::class.java,1000)
//                    finish()
                }
            }
        })


//        launchOnlyresult({
//
//        }, {
//            Log.i(TAG, "getMain: $it")
//            if (it?.id != null) {
//                MVUtils.put("token", it.id)
//                startActivity(MainActivity::class.java)
//            } else {
//            }
//        })

    }



}